package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.MemberDao01;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service(interfaceClass = MemberService01.class)
@Transactional
public class MemberServiceImpl01 implements MemberService01 {
    @Autowired
    private MemberDao01 memberDao01;

    @Override
    public void add(Member member) {
        memberDao01.add(member);

    }

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage, pageSize);
        Page<Member> page = memberDao01.selectByCondition(queryString);
        long total = page.getTotal();
        List<Member> rows = page.getResult();
        PageResult pageResult = new PageResult(total, rows);
        return pageResult;
    }

    @Override
    public boolean deleteById(Integer id) {
        return memberDao01.deleteById(id);
    }

    @Override
    public void edit(Member member) {

    }
}
